package com.tjp.eight.ui.fragment.whozan;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tjp.eight.R;
import com.tjp.eight.views.CircleImageView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/3/2.
 */
public class WhoZanAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<WhoZanResultModel.WZListModel> models;

    public WhoZanAdapter(Context context) {
        this.context = context;
        models = new ArrayList<>();
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_who_zan, parent, false);
        return new WhoZanViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((WhoZanViewHolder) holder).tv_user_name.setText(models.get(position).name);
        ((WhoZanViewHolder) holder).tv_who_zan_time.setText(models.get(position).pass_time);
        Glide.with(context).load(models.get(position).iconurl).error(R.drawable.icon_login).into(((WhoZanViewHolder) holder).civ_user_pic);
    }

    @Override
    public int getItemCount() {
        return models.size();
    }

    public void addData(WhoZanResultModel models) {
        if (models == null || models.data == null || models.data.isEmpty()) return;
        for (WhoZanResultModel.WZListModel whoZanResultModel : models.data) {
            this.models.add(whoZanResultModel);
        }
        notifyItemChanged(getItemCount());
        notifyDataSetChanged();
    }

    class WhoZanViewHolder extends RecyclerView.ViewHolder {
        CircleImageView civ_user_pic;
        TextView tv_user_name;
        TextView tv_who_zan_time;

        public WhoZanViewHolder(View itemView) {
            super(itemView);
            civ_user_pic = (CircleImageView) itemView.findViewById(R.id.civ_user_pic);
            tv_user_name = (TextView) itemView.findViewById(R.id.tv_user_name);
            tv_who_zan_time = (TextView) itemView.findViewById(R.id.tv_who_zan_time);
        }
    }
}
